#include "src/dbwrapper.h"

using std::cin;
using std::cout;
using std::endl;
using std::string;

const string db_path = "./mydb1";

int main() {
  cout << "-------- start testing" << endl;
  cout << "-------- start building db" << endl;
  DBWrapper db(DBOptions(), db_path);
  cout << "-------- start creating random keys" << endl;
  cout << "input a string: ";
  string s = "";
  cin >> s;
  if (s.empty()) {
    cout << "invalid" << endl;
    return 0;
  }
  cout << "keys root: " << s << endl;
  cout << "-------- start putting keys" << endl;
  for (const auto& c : s) {
    auto key = string(2, c), value = string(int(c), c);
    auto res = db.Put(key, value);
    cout << res << " ";
  }
  cout << endl;

  cout << "-------- start geting keys" << endl;
  for (const auto& c : s) {
    auto key = string(2, c);
    auto value = db.Get(key);
    cout << "\t[" << key << ": " << value << "]" << endl;
  }

  cout << "-------- start random get" << endl;
  for (int i = 0; i < 256; ++i) {
    auto key = string(2, char(i));
    auto value = db.Get(key);
    cout << "\t[" << key << ": " << value << "]" << endl;
  }

  cout << "-------- start walking" << endl;
  auto it = db.Iterator();
  for (it.SeekToFirst(); it.Valid(); it.Next()) {
    cout << "\t[" << it.key() << ": " << it.value() << "]" << endl;
  }

  cout << "-------- start random del" << endl;
  for (int i = 0; i < 256; ++i) {
    auto key = string(2, char(i));
    auto res = db.Del(key);
    cout << "\t[" << key << ": " << res << "]" << endl;
  }

  cout << "-------- succeed!" << endl;
}